package com.kui.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.kui.entity.Qikan;
import com.kui.util.DBHelp;
import com.kui.util.RowMapper;

public class QikanDao {

	DBHelp<Qikan> db = new DBHelp<Qikan>();
	private class QikanRowMapper implements RowMapper<Qikan>{

		public Qikan mapperRow(ResultSet rs) throws SQLException {
			Qikan q = new Qikan();
			q.setId(rs.getString("id"));
			q.setName(rs.getString("name"));
			return q;
		}
		
	}
	public void save(Qikan q) {
		String sql = "INSERT INTO t_qikan(id,name) VALUES(?,?)";
		db.executeSQL(sql, q.getId(),q.getName());
	}
	public Qikan findById(String bianhao) {
		String sql = "SELECT id,name FROM t_qikan WHERE id = ?";
		return db.executeQueryForObject(sql, new QikanRowMapper(), bianhao);
	}
	public List<Qikan> findAll() {
		String sql = "SELECT id,name FROM t_qikan";
		return db.executeQueryForList(sql, new QikanRowMapper());
	}
}
